[ 'method' => "GET", 'header' => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) PHP-Reader\r\n" ] ]; $context = stream_context_create($options); $xml_content = @file_get_contents($rss_url, false, $context); if ($xml_content === false) { die("Не вдалося завантажити RSS."); } $rss = simplexml_load_string($xml_content); // Початок формування HTML $html_output = "\n\n\n"; $html_output .= "\n"; $html_output .= "\n"; $html_output .= "MAXSITE.ORG - RSS Новини\n"; $html_output .= "\n"; $html_output .= "\n\n
\n"; $html_output .= "

MAXSITE.ORG

\n\n"; foreach ($rss->channel->item as $item) { $title = htmlspecialchars_decode((string)$item->title); $link = (string)$item->link; // Форматування дати $date = new DateTime($item->pubDate); $formattedDate = $date->format('d-m-Y H:i'); $description = (string)$item->description; // Пошук зображення preg_match('/https?:\/\/[^"\'>]+\.(?:jpg|jpeg|png|gif|webp)/i', $description, $matches); $img_src = $matches[0] ?? ''; // 1. ВИЛУЧЕННЯ тегів

разом із вмістом $description_filtered = preg_replace('/]*>.*?<\/p>/is', '', $description); // 2. Вилучення порожніх або "сміттєвих" пар тегів

$description_filtered = preg_replace('/]*>\s*( )*\s*<\/p>/i', '', $description_filtered); // 3. Очищення від решти HTML-тегів $clean_description = strip_tags($description_filtered); // 4. Очищення від зайвих пробілів $clean_description = trim($clean_description); // Формування блоку новини в HTML $html_output .= "

\n"; $html_output .= "
\n"; $html_output .= " {$title}\n"; $html_output .= " {$formattedDate}\n"; $html_output .= "
\n"; $html_output .= "
\n"; if ($img_src) { $html_output .= "
\n"; $html_output .= " " . htmlspecialchars($title) . "\n"; $html_output .= "
\n"; } $html_output .= "
{$clean_description}
\n"; $html_output .= "
\n"; $html_output .= "
\n"; } $html_output .= "
\n\n"; // Створюємо директорію Новини RSS, якщо її немає $dir = __DIR__ . '/Новини RSS'; if (!is_dir($dir)) { mkdir($dir, 0777, true); } // Збереження результату $filename = $dir . '/Новини вебмайстра.html'; file_put_contents($filename, $html_output); ?>